﻿@{
    ViewBag.Title = "供应商订单";

}
@section styles{
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/system.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/contract.css" type="text/css" rel="stylesheet" />
}
<style>
    a {
        text-decoration: none;
    }

    .brand_logo {
        width: 28px;
        height: 28px;
    }

    .hidden {
        display: none;
    }

    .layui-upload-img {
        max-width: 300px;
        max-height: 200px;
    }
</style>
<div class="layui-fluid layui-content">
    <div class="layui-title layui-clear layui-row">
        <h2 class="layui-col-md10 layui-col-sm9 layui-col-xs7">@ViewBag.Title</h2>
        <div class="layui-col-md2 layui-col-sm3 layui-col-xs5 layui-nav-item">
            <a class="layui-btn layui-btn-xs" id="check"><i class="layui-icon">&#xe65e;</i>结算</a>
            <button type="button" class="layui-btn layui-btn-xs" onclick="Export()"><i class="layui-icon">&#xe63c;</i>导出</button>
        </div>
    </div>
    <div class="layui-eacher layui-row layui-clear">
        <form class="layui-clear">
            <div class="layui-form layui-clear">
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">
                        供应商：
                    </label>
                    <div class="layui-input-block">
                        <select class="layui-input" name="supplier" id="supplier">
                            @{var x = 0;}
                            @foreach (var item in ViewBag.Supplier)
                            {
                                if (x == 0)
                                {
                                    <option value="@item.SupplierName" selected="selected">@item.SupplierName</option>
                                }
                                else
                                {
                                    <option value="@item.SupplierName">@item.SupplierName</option>
                                }
                                x++;
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-group layui-col-pc1 layui-col-md2 layui-col-sm4 layui-col-xs6">
                    <label class="layui-form-label">
                        结算状态：
                    </label>
                    <div class="layui-input-block">
                        @*<input type="text" class="layui-input" name="orderNumber" id="orderNumber" />*@
                        <select name="settlementStatus" id="settlementStatus">
                            <option value=" " selected="selected">全部</option>
                            <option value="0">未结算</option>
                            <option value="1">已结算</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md1">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" id="search" type="button"> 搜索 </button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-data layui-table-container">
        <table class="layui-hide layui-table" id="layui-table" lay-filter="table"></table>
    </div>
</div>
<div id="Layer_ajax" class="deploy-plus"></div>
@*
    <script type="text/html" id="barDemo">
        {{#  if(d.settlementStatus==0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="settlement">结算</a>
        {{# } }}
    </script>*@
@section scripts{
    @*
        <script src="~/Theme/js/content.min.js?v=1.0.0"></script>*@
    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>
    <script src="~/js/main.js"></script>
    @*
        <script src="~/Theme/js/plugins/layer/laydate/laydate.js"></script>*@
    <script type="text/javascript">

        var layer,form, table, upload;
        layui.use(['form', 'layedit', 'laydate', 'tree', 'table', 'layer'], function () {
            var layedit = layui.layedit
                ,laydate = layui.laydate
                ,layer = layui.layer
                , form = layui.form;

            table = layui.table
            table.render({
                elem: "#layui-table",
                url: '@Url.Action("GetSupplierOrdersData")',
                cellMinWidth: 26,
                where: { supplier: $('#supplier').val()},
                height: 'full-150',
                cols: [[
                    { type: 'checkbox' },
                    { field: 'orderNumber', title: '订单号'},
                    {
                        field: 'orderTime', title: '下单时间', templet: function (d) {
                            var orderTime = new Date(d.orderTime);
                            return 'orderTime', top.dateFtt("yyyy-MM-dd hh:mm", orderTime);
                        }
                    },
                    { field: 'productName', title: '商品名称'},
                    { field: 'supplierName', title: '供应商名称'},
                    { field: 'productCount', title: '数量'},
                    { field: 'payPrice', title: '单价（￥）'},
                    { field: 'totalPrice', title: '支付金额（￥）'},
                    {
                        field: 'deliveryStatus', title: '发货状态', templet: function (d) {
                            if (d.deliveryStatus == "0") {
                                return "deliveryStatus", "未发货"
                            } else if (d.deliveryStatus == "1") {
                                return "deliveryStatus", "已发货"
                            } else if (d.deliveryStatus == "2") {
                                return "deliveryStatus", "已确认"
                            }
                        }
                    },
                    {
                        field: 'deliveryTime', title: '发货时间', templet: function (d) {
                            var deliveryTime = new Date(d.deliveryTime);
                            return 'deliveryTime', top.dateFtt("yyyy-MM-dd hh:mm", deliveryTime);
                        }
                    },
                    {
                        field: 'settlementStatus', title: '结算状态', templet: function (d) {
                            if (d.settlementStatus == "0") {
                                return "settlementStatus", "未结算"
                            } else if (d.settlementStatus == "1") {
                                return "settlementStatus", "已结算"
                            }
                        }
                    },
                    {
                        field: 'settlementTime', title: '结算时间', templet: function (d) {
                            if (d.settlementTime != null) {
                                var settlementTime = new Date(d.settlementTime);
                                return 'settlementTime', top.dateFtt("yyyy-MM-dd hh:mm", settlementTime);
                            } else {
                                return '';
                            }
                        }
                    },
                    //{ title: '操作', width: 213, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "idTest",
                page: true,
            });

            $("#check").on("click", function () {

                var checkStatus = table.checkStatus('idTest');

                if (checkStatus.data.length == 0) {
                    layer.msg("请选择需要结算的订单！");
                    return false;
                }
                var supplierId;
                var totalprice = 0;
                var str = "";
                for (var i = 0; i < checkStatus.data.length; i++)
                {
                    if (checkStatus.data[i].settlementStatus == 0) {
                        supplierId = checkStatus.data[i].supplierId;
                        totalprice = checkStatus.data[i].spcecostPrice * checkStatus.data[i].productCount + totalprice;
                        str = str + checkStatus.data[i].id + "|";
                    }
                }
                LayerOpen('订单结算', '/Supplier/Settlement?supplierId=' + supplierId + "&totalprice=" + totalprice+"&str="+str);
            });

            //监听工具条
            //table.on('tool(table)', function (obj) {
            //    var data = obj.data;
            //    if (obj.event === 'settlement') {
            //        LayerOpen("订单结算[" + data.orderNumber + "]", "/Supplier/Settlement?id=" + data.id + "&&supplierId=" + data.supplierId + "&&orderNumber=" + data.orderNumber+"&&totalPrice="+data.totalPrice);
            //    }
            //});

            $('#search').on('click', function () {
                table.reload('idTest', {
                    where: {
                        supplier: $('#supplier').val(),
                        settlementStatus: $('#settlementStatus').val()
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            })
        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })


        $(document).ready(function () {

        });
        var lock = false;//锁作为全局变量
        function LoadNewOpen(url) {
            if (lock) {
                return false;
            } else {
                lock = true;
            }
            $("#Layer_ajax").load(url, function (responseTxt, statusTxt, xhr) {
                if (statusTxt == "error") {
                    top.layer.msg('页面加载失败！', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                form.render('select')

                $.validator.unobtrusive.parse(this);
                var height = $("#Layer_ajax").height();
                layer.open({
                    type: 1,
                    shadeClose: true,
                    title: false,
                    closeBtn: 0,
                    scrollbar: false,
                    content: $("#Layer_ajax"),
                    area: ["600px", height],
                    success: function (layero, index) {
                        //锁关闭
                        lock = false;
                    },
                    end: function () {
                        $("#Layer_ajax").empty();
                    }
                })
            })
        }

        function LayerOpen(title, url) {
            var open = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['400px', '300px'],
                content: url,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                },
                end: function () {
                    //销毁后重新加载
                    table.reload('idTest', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    })
                }
            });
        }

        function Export() {
            var supplier = $('#supplier').val();
            var settlementStatus = $('#settlementStatus').val();
            window.location.href = "/Supplier/ExportSupplierOrderData?supplier=" + supplier + "&settlementStatus=" + settlementStatus;
        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            }, successInfo)
        }

    </script>
}
